//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.ruoyi.live.configuration;

import com.ruoyi.live.base.domain.SystemClass;
import com.ruoyi.live.base.domain.User;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;

public class SessionInfo {
    public SessionInfo() {
    }

    public static Object get(SessionName key) {
        HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
        HttpSession sess = request.getSession();
        return sess == null ? null : sess.getAttribute(key.name());
    }

    public static Long getUserId() {
        return com.ruoyi.common.utils.SecurityUtils.getUserId();
    }

    public static Long getClassId() {
        HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
        HttpSession sess = request.getSession();
        if (sess != null) {
            Object cls = sess.getAttribute(SessionName.Cls.name());
            if (cls != null) {
                SystemClass cs = (SystemClass)cls;
                return cs.getId();
            }
        }

        return null;
    }

    public static User getUser() {
        HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
        HttpSession sess = request.getSession();
        if (sess != null) {
            Object user = sess.getAttribute(SessionName.User.name());
            if (user != null) {
                return (User)user;
            }
        }

        return null;
    }

    public static void set(SessionName key, Object value) {
        HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
        HttpSession sess = request.getSession();
        if (sess != null) {
            sess.setAttribute(key.name(), value);
        }
    }
}
